/* 
 * Created on 16. September 2008, 17:00
 *
 *      Copyright 2008 Oliver Eichner <o.eichner@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

/**
 * @file CommentDialog.cpp
 * Dialog class for AddComment dialog
 */

#include <ios>

#include "CommentDialog.h"

/**
 * @brief Create a dialog to add a comment to a device
 */
CommentDialog::CommentDialog(Device nDevice)
: Gtk::Dialog("Add comment", true),
cd_HBox(false, 8),
cd_label("Comment:", true),
cd_image(Gtk::Stock::EDIT, Gtk::ICON_SIZE_DIALOG) {

    add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);

    cd_HBox.set_border_width(8);
    get_vbox()->pack_start(cd_HBox, Gtk::PACK_SHRINK);

    cd_HBox.pack_start(cd_image, Gtk::PACK_SHRINK);

    cd_HBox.add(cd_VBox);
    cd_VBox.add(cd_label);
    cd_label.set_mnemonic_widget(cd_TextView);

    Glib::RefPtr<Gtk::TextBuffer> refBuffer = cd_TextView.get_buffer();
    Gtk::TextBuffer::iterator iter = refBuffer->get_iter_at_offset(0);
    iter = refBuffer->insert(iter, nDevice.getComment());
    //cd_entry.set_text(nDevice.getComment());
    cd_VBox.add(cd_TextView);
    cd_TextView.set_tooltip_text("Enter your commente here");

    show_all();

}

CommentDialog::~CommentDialog() {
}

/**
 * @brief get the Text from the Comment Textiew
 * @return string
 */
string CommentDialog::getText() {
    Glib::RefPtr<Gtk::TextBuffer> refBuf = cd_TextView.get_buffer();
    Gtk::TextBuffer::iterator iter = refBuf->get_iter_at_offset(0);
    return iter.get_text(refBuf->end());
}



